
<h2 style='text-align:center'>砍价商品管理</h2>
<div id='MainFreeGoods_GoodsListArea'>
	<div style='display:flex'>
		<div style='flex:1'>
			<input type="text" id='MainFreeGoods_SearchInp' style='width:100%' />
		</div>
		<div>
			<button type='button' id='MainFreeGoods_SearchBtn'>搜索</button>
		</div>
	</div>
	<select id="MainFreeGoods_TypeSelect" style='width:100%'>
		<option value="all">全部</option>
		<option value="1">正常</option>
		<option value="2">已封禁</option>
	</select>


	<!--商品列表-->
	<div id='MainFreeGoods_GoodsList'></div>


	<!--分页-->
	<div id='MainFreeGoods_GoodsFpage' style='text-align:center;margin:20px auto'></div>


</div>



<script>
	var mfg_pnow = 1;	//当前页码

	var mfg_search = '';  //当前搜索值

	var mfg_info = ''; //页面临时数据容器

	function GetCurrentType(){	//获取当前选择的分类
		return $('#MainFreeGoods_TypeSelect').find('option:selected').val();
	}


	$('#MainFreeGoods_SearchBtn').click(function(){		//搜索按钮点击事件
		mfg_search = $('#MainFreeGoods_SearchInp').val().trim();
		GetFreeGoodsList();
	});


	$('#MainFreeGoods_TypeSelect').change(function(){	//类型选择事件
		GetFreeGoodsList();
	});



	GetFreeGoodsList();

	function GetFreeGoodsList(){		//获取砍价商品列表
		var data = {
			type:'GetFreeGoodsList',
			pnow:mfg_pnow,
			search:mfg_search,
			get_type:GetCurrentType()
		}
		sca(data,function(res){
			if(!/^\[.+\]$/.test(res)){
				$('#MainFreeGoods_GoodsList').html('');
				return;
			}
			mfg_info = JSON.parse(res);
			Parse_mfg_info();


		},'interface.php');

	}

	//解析砍价列表数据到元素
	function Parse_mfg_info(){
		var str = '';
		for(var i=0;i<mfg_info.length;i++){
			str += "<div style='display:flex;border-bottom:1px solid #fee;font-size:13px;margin:15px 0;'>";
			str += "<div style='border:1px solid #eef;width:100px;height:100px'>";
			if(mfg_info[i].banner){
				var img_addr = upyun_shop_img+mfg_info[i].banner;
			}else{
				var img_addr = '../Public/Image/base.png';
			}
			str += "<img src='"+img_addr+"' style='width:100%;height:100%' onerror=this.src='../Public/Image/base.png' alt='呵呵了' ></div>";
			str += "<div style='flex:1;padding:0 5px;box-sizing:border-box;color:#999'>";
			//标题
			str += "<div style='font-size:14px;height:40px;word-break:break-all;overflow:hidden;color:#333'>"+mfg_info[i].title+"</div>";		
			str += "<div style='height:20px;display:flex;margin:8px 0'>";
			//价格
			str += "<div style='flex:1;color:red;font-weight:bold'>￥："+mfg_info[i].price+"</div>";
			str += "</div>";

			str += "<div style='height:20px;display:flex'>";
			//状态
			switch(mfg_info[i].free_stat){
				case 1:case '1':var stat_str = '<text style="color:blue">正常</text>';break;
				case 2:case '2':var stat_str = '已封禁';break;
				default :
					var stat_str = '审核中';break;
			}
			str += "<div style='width:60px'>"+stat_str+"</div>";

			str += "<div style='flex:1;text-align:right'>";
			if(mfg_info[i].free_stat == 1){
				str += "<span style='padding:1px 7px;background:#aaf;color:#fff;border-radius:5px' onclick=FreeGoodsDisabled("+mfg_info[i].id+")>封禁</span>　";
			}
			str += "<span style='padding:1px 7px;background:#aaf;color:#fff;border-radius:5px' 	onclick=FreeCon_FreeGoodsOrders("+mfg_info[i].id+")>查看订单</span>　";
			str += "</div></div></div></div>";
		}
		$('#MainFreeGoods_GoodsList').html(str);
	}


	//封禁砍价商品
	function FreeGoodsDisabled(id){



		var data = {
			type:'ChangeFreeGoodsStat',
			id:id,
			stat:2
		};
		Ajax2(data,function(res){
			if(res && res > 0){
				A('操作成功！');
				for(var i=0;i<mfg_info.length;i++){
					if(mfg_info[i].id == id){
						mfg_info[i].free_stat = 2;
					}
				}
				Parse_mfg_info();
			}else{
				A('操作异常！');
			}
		});
	}

</script>